<?php
session_start();
date_default_timezone_set("PRC");
$conn = new mysqli("localhost", "root", "", "simple_weibo");
$conn->query("set names 'utf8'");

// 信息窗口
function show_msg($msg, $url)
{
    $win_str = "<meta http-equiv='refresh' content='3; url=" . $url . "' />
    <table width=200 border=1 align=center>
    <tr>
        <td align=center><strong>提示窗口</strong></td>
    </tr>
    <tr>
        <td align=center><p>" . $msg . "</p>
            <p>3秒后自动跳转！<a href='" . $url . "'>跳转</a></p>
        </td>
    </tr>
</table>";
    echo $win_str;
    exit();
}

// 登录功能
function login($user, $pw)
{
    global $conn;
    $sql = "select * from weibo_admin where admin_user='$user' and admin_password='$pw'";
    $res = $conn->query($sql);
    if ($res->num_rows > 0) {
        $row = $res->fetch_assoc();
        $_SESSION['adminuser'] = $row['admin_user'];
        show_msg("欢迎管理员" . $_SESSION['adminuser'] . "访问!", "A-index.php");
    } else {
        show_msg("用户名或密码错误!", "A-login.php");
    }
}

//退出登录
function logout(){
    session_destroy();
    show_msg("退出登录","A-login.php");
}